import request from "@/request";
import { AxiosResponse } from "axios";
import ResultEnum from "@/config/ResultEnum";
import { message } from "ant-design-vue";

export const statusOptions = [
  {
    label: "正常",
    value: "Normal",
    color: "#2db7f5",
  },
  {
    label: "禁用",
    value: "Disable",
    color: "#87d068",
  },
];

//表格列
export const tableCols = [
  {
    title: "#",
    dataIndex: "idx",
    key: "idx",
    width: 50,
  },
  {
    title: "标签",
    dataIndex: "tagLabel",
    key: "tagLabel",
  },
  {
    title: "分组",
    dataIndex: "groupKeyTxt",
    key: "groupKeyTxt",
  },
  {
    title: "状态",
    key: "status",
  },
  {
    title: "创建时间",
    key: "createdTime",
    dataIndex: "createdTime",
  },
  {
    title: "操作",
    width: "180px",
    key: "actions",
  },
];

//获取数据
export const loadTable = (params: any) => {
  return request({
    url: "/tags/list",
    method: "get",
    params,
  });
};

export const changeStatus = (id: string, status: string) => {
  return request({
    url: "/tags/" + id + "/" + status,
    method: "post",
  });
};

export const getTagGroupKeys = () => {
  return new Promise((resolve: any, reject: any) => {
    request({
      url: "/tags/groups",
      method: "get",
    }).then((res: any) => {
      if (res.code == ResultEnum.SUCCESS_CODE) {
        let result = res.result;
        let arr = [] as any;
        for (let item of result) {
          arr.push({
            label: item.name,
            value: item.value,
          });
        }
        resolve(arr);
      }
    });
  });
};

export const submitDel = (id: string) => {
  return request({
    url: "/tags/" + id,
    method: "delete",
  });
};
